﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Common;
using Persistence.Dao;
using Domain;
using Persistence;
namespace web
{
    public partial class leaveWord : System.Web.UI.Page
    {     
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindList();
            }
        }

        private void BindList()
        {
            string what = "*";
            string where = "1=1";
            string orderBy = "id desc";
            IList<Leaveword> list = Singleton<LeavewordDao>.Instance.GetModels(what, where, orderBy, anp.PageSize, anp.CurrentPageIndex);
            if (list.Count > 0)
            {
                rptList.Visible = true;
                rptList.DataSource = list;
                rptList.DataBind();
            }
            else
            {
                rptList.Visible = false;
            }
        }
        protected void anp_PageChanged(object sender, EventArgs e)
        {
            BindList();
        }
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            Leaveword entity_Leaveword = new Leaveword();
            entity_Leaveword.title = txt_Leaveword_title.Value.Trim();
            entity_Leaveword.leavewordContent = txt_Leaveword_leavewordContent.Value.Trim();
            entity_Leaveword.addtime = DateTime.Now;
            entity_Leaveword.messagerName = txt_Leaveword_messagerName.Value.Trim();
            entity_Leaveword.messagerEmail = txt_Leaveword_messagerEmail.Value.Trim();
            entity_Leaveword.messagerTel = txt_Leaveword_messagerTel.Value.Trim();
            bool bResult = false;
            if (entity_Leaveword.title == "" && entity_Leaveword.leavewordContent == "")
            {
                Message.alert("留言内容必须填写");
                return;
            }
            try
            {
                Singleton<LeavewordDao>.Instance.Insert(entity_Leaveword);
                bResult = true;
            }
            catch { }

            if (bResult)
            {
                Message.alert("操作成功");
                BindList();
                txt_Leaveword_title.Value = "";
                txt_Leaveword_leavewordContent.Value = "";
                txt_Leaveword_messagerName.Value = "";
                txt_Leaveword_messagerEmail.Value = "";
                txt_Leaveword_messagerTel.Value = "";
            }
            else
            {
                Message.alert("操作失败，请检查您的数据");
            }
        }
    }
}
